<template>
  <div class="basic_info">
    <div class="info_operation_btn">
      <div class="btn_left">
        <el-button
          type="primary"
          @click="onShowAdd"
          style="width: 100px"
          :disabled="!isOpenAccount"
          :class="!isOpenAccount ? 'disabled_button' : ''"
          >新增往来单位</el-button
        >
        <el-button :disabled="!isOpenAccount" :class="!isOpenAccount ? 'disabled_button' : ''" @click="onSaveData"
          >保存</el-button
        >
        <el-button @click="onLookDetails()" :disabled="total === 0" :class="total === 0 ? 'disabled_button' : ''"
          >查看详情</el-button
        >
        <el-button :disabled="!isOpenAccount" :class="!isOpenAccount ? 'disabled_button' : ''" @click="importExcel"
          >导入</el-button
        >
        <!-- <el-select v-model="importValue">
          <el-option
            label="导入"
            value="导入"
            :disabled="!isOpenAccount"
            :style="!isOpenAccount ? 'pointer-events: none;font-size: 12px' : 'font-size: 12px'"
            @click.native="importExcel"
          ></el-option>
          <el-option
            label="导出"
            value="导出"
            :style="'font-size: 12px'"
            @click.native="exportExcel"
          ></el-option>
        </el-select> -->
        <el-checkbox v-model="queryData.status">显示禁用供应商</el-checkbox>
      </div>
      <div class="btn_right">
        <el-input
          @change="onQuery"
          v-model="queryData.queryParam"
          placeholder="请输入往来单位名称\拼音码\编码搜索"
        ></el-input>
        <el-button type="primary" @click="onQuery">搜索</el-button>
        <el-button @click="onRefresh">刷新</el-button>
        <i @click="onShowColumn" class="set_up el-icon-s-tools"></i>
      </div>
    </div>
    <div class="info_content_div">
      <div class="div_tree" :class="editTreeDataSta == false ? 'new_div_tree_width' : ''">
        <div class="tree_div1">
          <p>往来单位类别</p>
          <p v-if="editTreeDataSta && isOpenAccount" @click="editTreeDataSta = false">编辑</p>
          <el-button v-else-if="isOpenAccount" type="primary" @click="editTreeDataSta = true">完成编辑</el-button>
          <p v-else></p>
        </div>
        <div class="tree_input">
          <p>
            <input type="text" placeholder="查找" v-model="filterText" />
            <span>
              <i class="el-icon-search"></i>
            </span>
          </p>
        </div>
        <div class="tree_structure">
          <el-tree
            ref="tree"
            :data="treeData"
            node-key="label"
            :props="defaultProps"
            highlight-current
            default-expand-all
            :expand-on-click-node="false"
            @node-click="handleNodeClick"
            :filter-node-method="filterNode"
          >
            <span v-if="editTreeDataSta == false" class="tree_node" slot-scope="{ node, data }">
              <span class="tree_label">{{ node.label }}</span>
              <span v-if="nowLabel == data.id" class="show_nodex">
                <i class="el-icon-circle-plus-outline" @click.stop="onAddTree(data)"></i>
                <i v-if="data.id !== '0'" class="el-icon-edit-outline" @click.stop="onEditTree(node, data)"></i>
                <i v-if="data.id !== '0'" class="el-icon-delete" @click.stop="onDeleteTree(data)"></i>
              </span>
            </span>
            <span v-else class="tree_node" slot-scope="{ node }">
              <span class="tree_label">{{ node.label }}</span>
            </span>
          </el-tree>
        </div>
      </div>
      <div class="div_table" :class="editTreeDataSta == false ? 'new_div_table_width' : ''">
        <div class="table_content">
          <el-table
            ref="tableRef"
            :data="tableData"
            height="100%"
            border
            tooltip-effect="dark"
            highlight-current-row
            :header-cell-style="{ background: '#EDEDED', color: '#666666', textAlign: 'center' }"
            @selection-change="handleSelectionChange"
            show-summary
            :summary-method="getSummaries"
            @row-dblclick="handleRowDbclick"
            @row-click="onClickTable"
          >
            <el-table-column type="selection" :resizable="false"></el-table-column>
            <el-table-column :resizable="false" label="序号" type="index" width="50"></el-table-column>
            <el-table-column label="操作" :resizable="false" width="80px" v-if="isOpenAccount">
              <template slot-scope="scope">
                <i @click.stop="onEditRow(scope.row)" class="el-icon-edit-outline"></i>
                <i @click.stop="onDeleteRow(scope.row)" class="el-icon-delete"></i>
              </template>
            </el-table-column>
            <template v-for="(item, i) in columnData">
              <el-table-column
                :key="i"
                :show-overflow-tooltip="true"
                :prop="item.props"
                :label="item.zidingyiName ? item.zidingyiName : item.morenName"
                min-width="150px"
                v-if="item.zidingyiState"
                :resizable="false"
                :width="item.cellWidth"
              >
                <template slot-scope="scope">
                  <div class="index_input" style="padding: 0 5px">
                    <input
                      v-if="
                        ['beginReceivableShow', 'beginPayableShow', 'receivableQuotaShow', 'payableQuotaShow'].includes(
                          item.props
                        ) && isOpenAccount
                      "
                      v-model="scope.row[item.props]"
                      @blur="handleMoney(scope.row, item.props)"
                      @input="inputMoney(item.props, scope.row)"
                      @dblclick.stop="onDblclick"
                    />
                    <div v-else>
                      {{ scope.row[item.props] }}
                    </div>
                  </div>
                </template>
              </el-table-column>
            </template>
          </el-table>
        </div>
        <div class="table_pagination">
          <div class="pagination_div">
            <el-pagination
              background
              @size-change="handleSizeChange"
              @current-change="handleCurrentChange"
              :current-page="currentPage"
              :page-sizes="[20, 50, 100, 200]"
              :page-size="pagesize"
              layout="jumper, prev, pager,next, sizes"
              :total="total"
            ></el-pagination>
          </div>
        </div>
      </div>
    </div>
    <!-- 列配置弹框 -->
    <CConfiguration
      ref="setColumnRef"
      :columnDataArr="columnData"
      :defaultColumnDataArr="defaultColumnData"
      orderType="期初应收应付录入"
      @onSaveColumn="onSaveColumn"
    ></CConfiguration>
    <!-- 新增树形结构数据弹框 -->
    <el-dialog
      :title="this.newTreeData.module.name == 'deptName' ? '部门' : '类别信息'"
      :visible.sync="showNewTree"
      width="480px"
    >
      <NewCategory
        :newTreeData="newTreeData"
        @onSaveTreeChanges="onSaveTreeChanges"
        @onCancelTree="showNewTree = false"
      ></NewCategory>
    </el-dialog>
    <!-- 新增往来单位弹框 -->
    <DialogSupplierAdd
      ref="supplierAddRef"
      from='qichu'
      :newData="newData"
      @dialogVisibleClose="onCloseAddSupplier"
      @onAddSubmit="onAddSupplier"
    ></DialogSupplierAdd>
    <!-- 提醒弹框 -->
    <PopupReminder ref="reminderRef" :tipsData="tipsData" @dialogVisibleClose="onNo" @onConfirm="onYes"></PopupReminder>
    <!-- 成功弹框 -->
    <PopupSuccess ref="successRef" :tipsData="tipsData"></PopupSuccess>
    <!-- 导入 -->
    <DialogImport
      ref="daoru"
      :titles="columnData"
      url="/xghCompany/xghCompany/importCollectionExcel"
      @importData="importData"
      @downloadTemplate="exportExcel"
    ></DialogImport>
  </div>
</template>

<script>
import { mapGetters } from 'vuex'
import { regionData, CodeToText } from 'element-china-area-data'
import CConfiguration from '@/components/c_column/columnConfiguration1'
import NewCategory from '@/components/c_category/NewCategory'
import DialogSupplierAdd from '../../components/dialogSupplierAdd'
import DialogSupplierEdit from '../../components/dialogSupplierEdit'
import PopupReminder from '../../components/popupReminder'
import PopupSuccess from '../../components/popupSuccess'
import DialogImport from '@/components/c_Import/index1'
import { postAction, getAction, deleteAction, downPostFile } from '@/api/manage'
import { JeecgListMixin } from '@/mixins/JeecgListMixin'
// 导入调用处理权限数据方法
import {
  handlePermissions,
  handleOtherPerms,
  formatMoney,
  formatPrice,
  formatNumber,
  formatFour,
  delcommafy,
} from '@/utils/index'
export default {
  name: 'arAndapEntry',
  mixins: [JeecgListMixin],
  components: {
    CConfiguration,
    NewCategory,
    DialogSupplierAdd,
    DialogSupplierEdit,
    PopupReminder,
    PopupSuccess,
    DialogImport,
  },
  computed: {
    ...mapGetters(['name']),
  },
  created() {
    // this.companyPermissions = handlePermissions('往来单位')
    this.getData()
  },
  updated() {
    this.$nextTick(() => {
      this.$refs.tableRef.doLayout()
    })
  },
  watch: {
    'queryData.status': {
      deep: true,
      handler() {
        this.getTableData()
      },
    },
    filterText(val) {
      this.$refs.tree.filter(val)
    },
    tableData: {
      immediate: true,
      handler() {
        setTimeout(() => {
          const table = document.querySelector('.el-table__footer-wrapper>table')
          let tds = table.rows[0].cells
          tds[1].colSpan = 2
          tds[2].style.display = 'none'
          let cell = tds[1].childNodes[0]
          cell.style.justifyContent = 'flex-start'
          cell.style.paddingLeft = '5px'
        }, 0)
      },
    },
    // 路由变化时，更新数据
    $route: {
      immediate: true,
      handler(val) {
        if (val.name === 'baseInfomation-beginningOfPeriod-arAndapEntry') {
          // 获取开账方式
          this.getOpenAccountFlag()
        }
      },
    },
  },
  data() {
    return {
      // 存储按钮权限数据
      buttonsPermissions: {},
      companyPermissions: {},
      queryData: {
        status: false,
        queryParam: '',
        xghCompanyTypeId: '',
      },
      // 传递给弹框的数据
      tipsData: {
        tipsState: '',
        tipsWords: '',
        tipsMark: '',
      },
      pagesize: 20, //每页的数据条数
      currentPage: 1, //默认开始页面
      total: 0, //总条数
      nowLabel: '',
      // 状态按钮数据------------
      importValue: '导入',
      batchData: [], // 存储多选的数据
      // 树形结构数据------------
      showNewTree: false, //显示树形结构数据新增弹框
      // 传递数据给新增树形结构组件
      newTreeData: {
        parentData: '',
        data: '',
        state: '',
        module: {
          name: '',
        },
      },
      editTreeDataSta: true, //编辑单位类别状态
      companyTypeName: '', //类别查找值
      // 类别数据
      treeData: [],
      defaultProps: {
        children: 'children',
        label: 'label',
      },
      // 表格数据------------
      tableData: [],
      // 列配置数据
      defaultColumnData: [],
      columnData: [
        {
          morenName: '单位名称',
          zidingyiName: '',
          morenState: true,
          cellWidth: '150px',
          zidingyiState: true,
          isRequired: true,
          noModify: true,
          props: 'companyName',
        },
        {
          morenName: '单位编码',
          zidingyiName: '',
          morenState: true,
          cellWidth: '150px',
          zidingyiState: true,
          noModify: false,
          props: 'companyNumber',
        },
        {
          morenName: '单位类别',
          zidingyiName: '',
          morenState: true,
          cellWidth: '150px',
          zidingyiState: true,
          noModify: false,
          props: 'xghCompanyTypeId_dictText',
        },
        {
          morenName: '地址',
          zidingyiName: '',
          morenState: true,
          cellWidth: '150px',
          zidingyiState: true,
          noModify: false,
          props: 'address',
        },
        {
          morenName: '联系人',
          zidingyiName: '',
          morenState: true,
          cellWidth: '150px',
          zidingyiState: true,
          noModify: false,
          props: 'companyUserName',
        },
        {
          morenName: '手机',
          zidingyiName: '',
          morenState: true,
          cellWidth: '150px',
          zidingyiState: true,
          noModify: false,
          props: 'companyPhone',
        },
        {
          morenName: '联系电话',
          zidingyiName: '',
          morenState: true,
          cellWidth: '150px',
          zidingyiState: true,
          noModify: false,
          props: 'companyLandline',
        },
        {
          morenName: '期初应收款',
          zidingyiName: '',
          morenState: true,
          cellWidth: '150px',
          zidingyiState: true,
          noModify: false,
          props: 'beginReceivableShow',
        },
        {
          morenName: '期初应付款',
          zidingyiName: '',
          morenState: true,
          cellWidth: '150px',
          zidingyiState: true,
          noModify: false,
          props: 'beginPayableShow',
        },
        {
          morenName: '应收信用额度',
          zidingyiName: '',
          morenState: true,
          cellWidth: '150px',
          zidingyiState: true,
          noModify: false,
          props: 'receivableQuotaShow',
        },
        {
          morenName: '应付信用额度',
          zidingyiName: '',
          morenState: true,
          cellWidth: '150px',
          zidingyiState: true,
          noModify: false,
          props: 'payableQuotaShow',
        },
      ],
      // 新增数据------------
      newData: {
        companyName: '',
        companyUserName: '',
        xghCompanyNatureId: '',
        xghCompanyNature: '',
        companyPhone: '',
        companyPinyinCode: '',
        companyLandline: '',
        xghCompanyTypeId: '', //单位类别
        companyTypeName: '',
        business: '',
        provinceName: '', //省
        provinceCode: '',
        cityName: '', //市
        cityCode: '',
        countyName: '', //区县
        countyCode: '',
        address: '',
        setPrice: '',
        setDiscountPrice: '',
        companyInvoiceStatus: false, //开票信息
        depositBank: '',
        bankName: '',
        bakCard: '',
        taxNumber: '',
        invoiceAddress: '',
        bankPhone: '',
        companyRAndPStatus: false, //应收应付
        beginReceivable: 0,
        beginPayable: 0,
        totalReceivable: 0,
        totalPayable: 0,
        receivableQuota: '',
        payableQuota: '',
        receivableTime: '',
        payableTime: '',
        companyRemark: '',
        companyNumber: '', //单位编码
        companyNationality: '中国',
      },
      ssqOptions: regionData, //省市区选项
      selectedOptions: [], //省市区
      nowTreeId: '', //暂存删除树形节点id
      nowData: {}, //暂存当前行数据
      nowStatus: '', //暂存启用禁用下拉框状态
      nowDataId: '', //暂存删除表数据id
      updateId: '', // 修改列配置时返回的id
      filterText: '',
      isOpenAccount: false, // 开账后不能修改
      url: {
        companyList: '/xghCompany/xghCompany/list',
        api: '期初应收应付录入',
        exportXlsUrl: '/xghCompany/xghCompany/exportCollectionXls',
      },
      moneyLength: 2,
    }
  },
  mounted() {
    // 初始化列配置数据
    this.defaultColumnData = JSON.parse(JSON.stringify(this.columnData))
    this.selectTitle()
    let unititem = this.$lcStorage.get('toFixedList')
    if (unititem) {
      this.moneyLength = unititem.allPrice
    }
  },
  methods: {
    // 选中当前行
    onClickRow(row) {
      this.$refs.tableRef.toggleRowSelection(row)
    },
    filterNode(value, data) {
      if (!value) return true
      return data.label.indexOf(value) !== -1
    },
    // 初始化查询列配置值
    async selectTitle() {
      let obj = await this.$setColumn.selectColumn(this.url.api)
      if (obj.code === 200) {
        this.updateId = obj.updateId
        this.columnData = obj.columnData
      } else if (obj.code === 500) {
        let id = await this.$setColumn.addColumn(this.url.api, this.$options.data().columnData)
        this.updateId = id
      }
    },
    // 修改列配置后保存修改后的值
    async onSaveColumn(value) {
      this.columnData = value
      let res = await this.$setColumn.editColumn(this.url.api, this.columnData, this.updateId)
      if (res.code == 200) {
        this.$elMessage.success(res.message)
      } else {
        this.$elMessage.error(res.message)
      }
    },
    // 获取数据
    getData() {
      this.getTreeData()
      this.getTableData()
    },
    // 获取类别数据
    getTreeData() {
      getAction('/xghCompanyType/xghCompanyType/childList', {}).then((res) => {
        if (res.code === 200) {
          let list = res.result
          let result = this.getTreeDataByList(list, '0', '')
          this.treeData = [
            {
              id: '0',
              label: '全部',
              children: result,
            },
          ]
        }
      })
    },
    getTreeDataByList(list, parentId, parentName) {
      let data = []
      for (let index = 0; index < list.length; index++) {
        const element = list[index]
        if (element.pid == parentId) {
          data.push({
            ...element,
            id: element.id,
            label: element.companyTypeName,
            parentId,
            parentName,
            children: this.getTreeDataByList(list, element.id, element.companyTypeName),
          })
        }
      }
      return data
    },
    // 获取表格数据
    getTableData() {
      let data = {
        ...this.queryData,
        pageSize: this.pagesize,
        pageNo: this.currentPage,
      }
      data.status = data.status ? '1' : '0'
      getAction(this.url.companyList, data).then((res) => {
        if (res.code === 200) {
          let result = res.result.records || []
          this.total = res.result.total
          result.forEach((item) => {
            item.beginReceivableShow = formatMoney(item.beginReceivable)
            item.beginPayableShow = formatMoney(item.beginPayable)
            item.receivableQuotaShow = formatMoney(item.receivableQuota)
            item.payableQuotaShow = formatMoney(item.payableQuota)
          })
          this.tableData = result
        }
      })
    },
    // 提醒弹框确认后操作
    onYes(mark) {
      if (mark == 'onDeleteRow') {
        let data = {
          id: this.nowDataId,
        }
        deleteAction('/xghCompany/xghCompany/deleteQiChu', data).then((res) => {
          if (res.code === 200) {
            this.$elMessage.success(res.message)
            let arr = this.$lcStorage.get('wldwHistoricalRecords')
            if (arr && arr.length > 0) {
              arr.forEach((item, index) => {
                if (item.id === this.nowDataId) {
                  arr.splice(index, 1)
                }
              })
              this.$lcStorage.set('wldwHistoricalRecords', arr)
            }

            this.getTableData()
          } else {
            this.$elMessage({
              showClose: true,
              message: res.message,
              type: 'error',
              iconClass: 'el-icon-warning-outline',
              duration: 3000,
            })
          }
        })
      } else if (mark == 'onDeleteTree') {
        let data = {
          id: this.nowTreeId,
        }
        deleteAction('/xghCompanyType/xghCompanyType/delete', data).then((res) => {
          if (res.code === 200) {
            // 删除的类别清除保存的数据
            if (this.newData.xghCompanyTypeId === this.nowTreeId) {
              this.newData.xghCompanyTypeId = ''
            }
            this.getTreeData()
          } else {
            this.$elMessage({
              showClose: true,
              message: res.message,
              type: 'error',
              iconClass: 'el-icon-warning-outline',
              duration: 3000,
            })
          }
        })
      }
    },
    // 提醒弹框确认后操作
    onNo(mark) {
      console.log('onNo')
      if (mark == 'onChangeStatus') {
        this.tableData.forEach((item) => {
          if (item.id == this.nowData.id) {
            item.status = !item.status
          }
        })
      }
    },
    // 打开新增数据弹框
    onShowAdd() {
      this.newData = this.$options.data().newData
      this.newData.typeEdit = 0
      this.$refs.supplierAddRef.dialogVisible = true
      this.$refs.supplierAddRef.reloadData()
    },
    handleMoney(val, key) {
      val[key.replace('Show', '')] = formatFour(val[key])
      val[key] = formatMoney(val[key])
    },
    // 搜索
    onQuery() {
      this.currentPage = 1
      this.getTableData()
    },
    // 合计列计算
    getSummaries(param) {
      const { columns, data } = param
      const sums = []
      columns.forEach((column, index) => {
        if (index === 0) {
          sums[index] = '合计'
        } else if (index === 1) {
          sums[index] = '共' + this.total + '条明细'
        } else if (
          column.property === 'beginReceivableShow' ||
          column.property === 'beginPayableShow' ||
          column.property === 'receivableQuotaShow' ||
          column.property === 'payableQuotaShow'
        ) {
          const values = data.map((item) => delcommafy(item[column.property]))
          if (!values.every((value) => isNaN(value))) {
            sums[index] = values.reduce((prev, curr) => {
              const value = delcommafy(curr)
              if (!isNaN(value)) {
                return prev + curr
              } else {
                return prev
              }
            }, 0)
            sums[index] = formatMoney(sums[index]) // 保留2位小数，解决小数列合计精度缺失的问题
          }
        } else {
          sums[index] = ''
        }
      })
      return sums
    },
    // 刷新
    onRefresh() {
      // 重置数据
      Object.assign(this.$data, this.$options.data())
      // this.buttonsPermissions = handlePermissions('期初应收应付录入')
      // this.companyPermissions = handlePermissions('往来单位')
      this.defaultColumnData = JSON.parse(JSON.stringify(this.columnData))
      this.selectTitle()
      this.getOpenAccountFlag()
      this.getTreeData()
    },
    // 触发列配置弹框
    onShowColumn() {
      this.defaultColumnData = this.$options.data().columnData
      this.$refs.setColumnRef.dialogVisible = true
    },
    // 搜索树形结构数据
    onSelectTree() {
      this.getTreeData()
    },
    // 触发树形当前节点
    handleNodeClick(data) {
      if (this.editTreeDataSta) {
        //非编辑状态
        if (this.queryData.xghCompanyTypeId != data.id) {
          this.queryData.xghCompanyTypeId = data.id == 0 ? undefined : data.id
          this.newData.xghCompanyTypeId = data.id == 0 ? '' : data.id
          this.getTableData()
        }
      } else {
        this.nowLabel = data.id
      }
    },
    // 触发新增树形节点按钮
    onAddTree(data) {
      this.newTreeData = {
        data: data,
        state: 'add',
        module: {
          name: 'companyTypeName', //类别名称字段
          code: 'companyCode', //类别编码字段
          pyCode: 'companyPinyinCode', //类别拼音码字段
          indexCode: 'companyIndexCode', //类别排序码字段
        },
        getTreeUrl: '/xghCompanyType/xghCompanyType/childList', //获取类别接口
        deleteTreeUrl: '/xghCompanyType/xghCompanyType/delete', //删除类别接口
        addTreeUrl: '/xghCompanyType/xghCompanyType/add', //新增类别接口
        editTreeUrl: '/xghCompanyType/xghCompanyType/edit', //修改类别接口
      }
      this.showNewTree = true
    },
    // 触发修改树形节点按钮
    onEditTree(node, data) {
      this.newTreeData = {
        data: data,
        state: 'edit',
        module: {
          name: 'companyTypeName', //类别名称字段
          code: 'companyCode', //类别编码字段
          pyCode: 'companyPinyinCode', //类别拼音码字段
          indexCode: 'companyIndexCode', //类别排序码字段
        },
        getTreeUrl: '/xghCompanyType/xghCompanyType/childList', //获取类别接口
        deleteTreeUrl: '/xghCompanyType/xghCompanyType/delete', //删除类别接口
        addTreeUrl: '/xghCompanyType/xghCompanyType/add', //新增类别接口
        editTreeUrl: '/xghCompanyType/xghCompanyType/edit', //修改类别接口
      }
      this.showNewTree = true
    },
    // 类别信息新增/修改后数据获取
    onSaveTreeChanges() {
      this.getTreeData()
      this.showNewTree = false
    },
    // 类别信息取消按钮触发
    onCancelTree() {
      this.showNewTree = false
    },
    // 触发删除树形节点按钮
    onDeleteTree(data) {
      if (data.children && data.children.length) {
        this.showTips('类别下级有分类，不允许删除！')
      } else {
        this.tipsData.tipsState = 'delete'
        this.tipsData.tipsWords = '是否确认删除?'
        this.tipsData.tipsMark = 'onDeleteTree'
        this.$refs.reminderRef.dialogVisible = true
        this.nowTreeId = data.id
      }
    },
    handleRowDbclick(val) {
      this.showSupplier(val)
    },
    onDblclick() {},
    // 查看详情
    onLookDetails() {
      if (this.batchData.length > 1) {
        this.showTips('只能选择一个往来单位！')
      } else if (this.batchData.length === 1) {
        const data = JSON.parse(JSON.stringify(this.batchData[0]))
        this.showSupplier(data)
      } else {
        this.showTips('请先选择一个往来单位！')
      }
    },
    showSupplier(data) {
      data.status = data.status == 0 ? true : false
      data.companyInvoiceStatus = data.companyInvoiceStatus == 0 ? true : false
      data.companyRAndPStatus = data.companyRAndPStatus == 0 ? true : false
      this.newData = Object.assign({}, this.newData, data)
      this.newData.typeEdit = 1
      this.$refs.supplierAddRef.dialogVisible = true
      this.$refs.supplierAddRef.reloadData()
    },
    // 触发表格修改按钮
    onEditRow(val) {
      this.newData = this.$options.data().newData
      val.status = val.status == 0 ? true : false
      val.companyInvoiceStatus = val.companyInvoiceStatus == 0 ? true : false
      val.companyRAndPStatus = val.companyRAndPStatus == 0 ? true : false
      this.newData = Object.assign({}, this.newData, val)
      this.$refs.supplierAddRef.dialogVisible = true
      this.$refs.supplierAddRef.reloadData()
    },
    // 删除当前行
    onDeleteRow(row) {
      this.tipsData.tipsState = 'delete'
      this.tipsData.tipsWords = '是否确认删除?'
      this.tipsData.tipsMark = 'onDeleteRow'
      this.$refs.reminderRef.dialogVisible = true
      this.nowDataId = row.id
    },
    // 获取新增客户数据
    onAddSupplier() {
      // this.getTableData()
      this.newData = this.$options.data().newData
    },
    // 获取修改客户数据
    onEditSupplier() {
      this.getData()
      this.newData = this.$options.data().newData
    },
    // 关闭新增往来单位时清空
    onCloseAddSupplier() {
      this.queryData.xghCompanyTypeId = ''
      this.getData()
      this.newData = this.$options.data().newData
    },
    // 关闭修改往来单位时清空
    onCloseEditSupplier() {
      this.getData()
      this.newData = this.$options.data().newData
    },
    // 获取每页几条数据
    handleSizeChange(val) {
      this.pagesize = val
      this.getTableData()
    },
    // 获取当前第几页
    handleCurrentChange(val) {
      this.currentPage = val
      this.getTableData()
    },
    // 触发表格多选按钮
    handleSelectionChange(val) {
      this.batchData = val
    },
    // 点击修改价格
    onClickTable(row) {
      if (this.batchData.indexOf(row) === -1) {
        this.$refs.tableRef.toggleRowSelection(row)
      }
    },
    // 导入数据
    importExcel() {
      this.$refs.daoru.dialogVisible = true
    },
    // 导入数据处理
    importData(val) {
      if (val.success) {
        this.showTips(val.message, 0)
        this.currentPage = 1
        this.getTableData()
        // val.result.forEach((item) => {
        //   this.tableData.forEach(data => {
        //     if (item.id === data.id) {
        //       data.companyName = item.companyName //单位名称
        //       data.companyNumber = item.companyNumber //单位编码
        //       data.xghCompanyTypeId_dictText = item.xghCompanyTypeId_dictText //单位类别
        //       data.address = item.address //地址
        //       data.companyUserName = item.companyUserName //联系人
        //       data.companyPhone = item.companyPhone //手机
        //       data.companyLandline = item.companyLandline //联系电话
        //       data.beginReceivable = item.beginReceivable ? formatMoney(item.beginReceivable) : item.beginReceivable //期初应收款
        //       data.beginPayable = item.beginPayable ? formatMoney(item.beginPayable) : item.beginPayable //期初应付款
        //       data.receivableQuota = item.receivableQuota ? formatMoney(item.receivableQuota) : item.receivableQuota //应收信用额度
        //       data.payableQuota = item.payableQuota ? formatMoney(item.payableQuota) : item.payableQuota //应付信用额度
        //     }
        //   })
        // })
      } else {
        this.showTips(val.message, 2)
      }
    },
    // 导出数据
    exportExcel() {
      // let list = []
      // if (this.batchData && this.batchData.length > 0) {
      //   for (let index = 0; index < this.batchData.length; index++) {
      //     const element = this.batchData[index]
      //     list.push(element.id)
      //   }
      // } else {
      //   this.$elMessage.warning('请选择想要导出的数据！')
      //   return
      // }
      let queryParam = {
        fileName: '期初应收应付录入',
        // selections: list.join(','),
      }
      this.handleExportXlsByStaff('期初应收应付录入', queryParam)
    },
    // 保存数据
    onSaveData() {
      if (this.batchData.length === 0) {
        return this.showTips('请先选择需要修改的往来单位！', 2)
      }
      let data = JSON.parse(JSON.stringify(this.batchData))
      postAction('/openAccount/enterOpeningCollectionAndPay', data).then((res) => {
        if (res.code === 200) {
          this.showTips(res.message, 0)
          this.getTableData()
        } else {
          this.showTips(res.message, 2)
        }
      })
    },
    // 控制输入不能超过限制位数
    inputMoney(key, val) {
      //首位不能输入"."
      val[key] = val[key].replace(/^\./g, '0.')
      val[key] = val[key].replace(/\.{2,}/g, '.') //只保留第一个. 清除多余的
      val[key] = val[key].replace('.', '$#$').replace(/\./g, '').replace('$#$', '.')
      if (this.moneyLength === 2) {
        // 小数点后面保留2位
        val[key] = val[key].replace(/^(\-)*(\d+)\.(\d\d).*$/, '$1$2.$3')
      } else {
        // 小数点后面保留4位
        val[key] = val[key].replace(/^(\-)*(\d+)\.(\d\d\d\d).*$/, '$1$2.$3')
      }
    },
    // 获取期初信息
    getOpenAccountFlag() {
      getAction('/openAccount/getOpenAccountType', {}).then((res) => {
        if (res.code === 200) {
          let val = Number(res.result.value)
          this.$store.commit('SET_OPEN_ACCOUNT_VALUE', val)
          if (val == 3) {
            this.isOpenAccount = false
          } else {
            this.isOpenAccount = true
          }
        }
      })
    },
    // 提醒弹窗
    showTips(msg, type = 1) {
      switch (type) {
        case 0:
          this.$elMessage.success(msg)
          break
        case 1:
          this.$elMessage.warning(msg)
          break
        case 2:
          this.$elMessage.error(msg)
          break
      }
    },
  },
}
</script>

<style lang="scss" scoped>
.basic_info {
  width: 100%;
  height: calc(100vh - 1.875117rem);
  background: #f0f2f5;
  box-sizing: border-box;
  padding: 0 0.168761rem 0.168761rem;
  display: flex;
  flex-direction: column;
}
.info_operation_btn {
  width: 100%;
  height: 50px;
  display: flex;
  align-items: center;
  .el-button {
    width: 70px;
    height: 30px;
    text-align: center;
    box-sizing: border-box;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 12px;
    border-radius: 0.1rem;
    border: none;
    margin-right: 6px;
  }
  .el-button--default {
    color: #666;
  }
  .btn_left {
    width: 50%;
    display: flex;
    justify-content: flex-start;
    align-items: center;
    ::v-deep .el-checkbox__label {
      font-size: 12px;
      padding-left: 0.1rem;
    }
    ::v-deep .el-select {
      width: 70px;
      height: 30px;
      box-sizing: border-box;
      margin-right: 14px;
      .el-input {
        .el-input__inner {
          height: 30px;
          border: none;
          font-size: 12px;
        }
        .el-input__suffix {
          height: 30px;
          display: flex;
          align-items: center;
        }
      }
    }
    .el-button {
      margin-left: 0px;
      margin-right: 6px;
    }
  }
  .btn_right {
    width: 50%;
    display: flex;
    justify-content: flex-end;
    align-items: center;
    .el-input {
      width: 4.725295rem;
      height: 30px;
      margin-right: 6px;
      ::v-deep .el-input__inner {
        height: 30px;
        border: none;
        box-sizing: border-box;
        padding: 0 5px;
        background: #fff;
        font-size: 12px;
        color: #666;
        &::placeholder {
          font-size: 12px;
          color: #c1c1c1;
        }
      }
    }
    .el-button {
      width: 70px;
      margin-left: 0;
    }
    .set_up {
      font-size: 23px;
      color: rgb(153, 153, 153);
    }
  }
}
.info_content_div {
  width: 100%;
  height: calc(100% - 1rem);
  background: #fff;
  box-sizing: border-box;
  padding: 0.168761rem;
  display: flex;
  .div_tree {
    width: 2.812676rem;
    height: calc(100% - 1rem);
    box-sizing: border-box;
    padding: 0.131258rem 0;
    border: 0.018751rem solid #e3e3e3;
    transition: all 0.3s;
    .tree_div1 {
      width: 100%;
      height: 0.337521rem;
      box-sizing: border-box;
      padding: 0 0.168761rem;
      display: flex;
      align-items: center;
      justify-content: space-between;
      p {
        color: #666666;
        font-size: 12px;
        margin-bottom: 0;
        &:last-child {
          color: #1b93f9;
        }
      }
      .el-button {
        width: 70px;
        height: 0.38rem;
        text-align: center;
        box-sizing: border-box;
        display: flex;
        align-items: center;
        justify-content: center;
        font-size: 12px;
        border-radius: 0;
        border: none;
      }
    }
    .tree_input {
      width: 100%;
      // height: 30px;
      height: 30px;
      margin-top: 0.131258rem;
      box-sizing: border-box;
      padding: 0 0.168761rem;
      p {
        width: 100%;
        // height: 30px;
        height: 30px;
        margin: 0;
        box-sizing: border-box;
        border: 1px solid #dddddd;
        display: flex;
        align-items: center;
        position: relative;
        input {
          width: 100%;
          box-sizing: border-box;
          padding: 0 5px;
          height: 28px;
          border: none;
          font-size: 12px;
          &:focus {
            outline: none;
          }
        }
        span {
          position: absolute;
          right: 0;
          display: flex;
          align-items: center;
          justify-content: center;
          width: 0.55rem;
          height: 28px;
          background: #fff;
          .el-icon-search {
            font-size: 0.25rem;
            color: rgb(211, 211, 211);
          }
        }
      }
    }
    .tree_structure {
      width: 100%;
      height: calc(100% - 0.337521rem - 0.131258rem - 0.131258rem - 0.55rem);
      box-sizing: border-box;
      padding: 0 0.168761rem;
      margin-top: 0.131258rem;
      overflow: auto;
      ::v-deep .el-tree {
        width: 100%;
        .tree_node {
          width: 100%;
          display: flex;
          align-items: center;
          justify-content: space-between;
          span {
            font-size: 12px;
          }
          .tree_label {
            width: 7em;
            overflow: hidden;
            text-overflow: ellipsis;
            white-space: nowrap;
          }
          .show_nodex {
            display: flex;
            align-items: center;
            font-size: 0.25rem;
            i {
              margin-right: 0.15rem;
              font-weight: 600;
            }
            .el-icon-circle-plus-outline {
              color: #1993fb;
            }
            .el-icon-edit-outline {
              color: #1993fb;
            }
            .el-icon-delete {
              color: #ff2626;
            }
          }
        }
        .el-tree-node__children {
          .el-tree-node__label {
            color: #666;
            font-weight: normal;
          }
        }
        .el-tree-node__label {
          font-size: 12px;
          font-weight: 600;
        }
        .is-current {
          .el-tree-node__content {
            background-color: #e6f7ff;
          }
        }
        .el-tree-node__content > .el-tree-node__expand-icon {
          padding-left: 0;
        }
      }
    }
  }
  .new_div_tree_width {
    width: 4.125258rem;
  }
  .div_table {
    width: calc(100% - 3rem);
    height: 100%;
    margin-left: 0.187512rem;
    display: flex;
    flex-direction: column;
    justify-content: space-between;
    transition: all 0.3s;
    .table_content {
      height: calc(100% - 0.337521rem - 0.131258rem - 0.131258rem - 0.55rem);
      ::v-deep .el-table {
        border: 1px solid #e3e3e3;
        border-bottom: none;
        box-sizing: border-box;
        th,
        td {
          padding: 0;
          color: #666;
          box-sizing: border-box;
          border-right: 1px solid #e3e3e3;
          .cell {
            min-height: 30px;
            display: flex;
            align-items: center;
            font-size: 12px;
            padding: 0;
          }
          &:first-child {
            .cell {
              justify-content: center;
              padding: 0;
            }
          }
          &:nth-child(2) {
            .cell {
              justify-content: center;
            }
          }
          &:last-child {
            .cell {
              justify-content: center;
            }
          }
        }
        th {
          .cell {
            display: block;
            line-height: 30px;
            background: #ededed;
            justify-content: center;
          }
        }
        .el-checkbox {
          .is-indeterminate {
            .el-checkbox__inner {
              color: #1b93f9;
              background-color: #1b93f9;
              border-color: #1b93f9;
            }
          }
        }
        .el-icon-edit-outline {
          font-size: 20px;
          color: #1b93f9;
          margin-right: 0.037502rem;
        }
        .el-icon-delete {
          font-size: 20px;
          color: #ff2626;
          margin-left: 0.037502rem;
        }
        .el-table__body tr:hover > td {
          background: #e3f6ff;
        }
        .el-table__footer-wrapper {
          td {
            background: #f4f4f4;
            border: none;
          }
        }
        //滚动条的宽度
        ::-webkit-scrollbar {
          width: 8px;
          height: 10px;
          background-color: #e5e5e5;
        }
        //滚动条的滑块
        ::-webkit-scrollbar-thumb {
          background-color: #c9c9c9;
        }
      }
    }
    .table_pagination {
      width: 100%;
      height: 50px;
      box-sizing: border-box;
      padding: 0.168761rem 0;
      display: flex;
      .pagination_div {
        width: 100%;
        display: flex;
        align-items: center;
        justify-content: flex-end;
        ::v-deep .el-pagination {
          padding: 0;
          height: 30px;
          .el-pagination__sizes {
            margin: 0;
            .el-input {
              margin-right: 0;
            }
          }
        }
      }
    }
  }
  .new_div_table_width {
    width: calc(100% - 4.31277rem);
  }
}
.disabled_button {
  background: #cbced3 !important;
  color: #666 !important;
}

.index_input {
  display: flex;
  align-items: center;
  height: 100%;
  width: 100%;

  input {
    width: 100%;
    height: 100%;
    border-radius: 0;
    background: #ffffff;
    border: none;
    color: #666;

    &:focus {
      outline: none;
      border: 1px solid #1b94fb;
    }
  }
}
</style>
